package com.example.zwx.myapplication;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    static int a[] = {9056, 4503, 574, 1689, 574, 560, 573, 561, 573, 561, 573, 561
            , 573, 561, 573, 561, 573, 557, 573, 561, 573, 1691, 573, 1690, 574,
            1690, 573, 1689, 574, 1689, 574, 1690, 573, 1690, 574, 1689, 573, 1690
            , 573, 1689, 574, 1689, 574, 1690, 574, 561, 574, 561, 574, 558, 574, 561
            , 574, 561, 574, 561, 574, 561, 574, 561, 574, 1691, 574, 1690, 574, 1689, 574, 39773};
    private BleManager mBleManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        mBleManager = BleManager.getInstance(this);
        mBleManager.init(new BleManager.ServiceInitListener() {
            @Override
            public void onResult(boolean result, String msg) {
                Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
                Log.d("123456", msg);
                if (result) {
                    mBleManager.connect2BondedDevice();
                }
            }
        });

        Button btn = (Button) findViewById(R.id.send_btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                mBleManager.sendIr(a, 0);
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mBleManager.destory();
    }
}
